package com.sx.manage.util;

import javax.annotation.Resource;

import com.sx.cache.Cache;
import com.sx.common.util.json.JackJsonUtil;
import com.sx.model.constants.MSystemConstants;
import com.sx.model.manage.mybatis.form.BaseForm;
import com.sx.model.manage.mybatis.vo.consumer.login.MConsumerLoginVO;

/**
 * 
 * @author Administrator
 *
 */
public class FormPageUtil {

	@Resource(name = "redisCache")
	protected Cache cache;
	/** 新增查询信息**/
	public static void addPage(Cache cache,BaseForm form,String keyStr,MConsumerLoginVO loginVO) {
		String key = FormPageConstants.FORM_PAGE+":"+keyStr+":"+loginVO.getConsumer_id();
		cache.set(key, JackJsonUtil.objToJson( form),"NX", "EX",MSystemConstants.SESSION_TIME_SET_UP);
	}
	/** 获取查询信息**/
	public static BaseForm  getPage(Cache cache,Class<?> cls,String keyStr,MConsumerLoginVO loginVO) {
		String key = FormPageConstants.FORM_PAGE+":"+keyStr+":"+loginVO.getConsumer_id();
		return (BaseForm)JackJsonUtil.jsonToJavaBean(cache.get(key),cls); 
	}
	/** 删除查询信息**/
	public static void clearPage(Cache cache,String keyStr,MConsumerLoginVO loginVO) {
		String key = FormPageConstants.FORM_PAGE+":"+keyStr+":"+loginVO.getConsumer_id();
		cache.del(key);
	}
	
	/** 删除查询信息**/
	public static  void resertPage(Cache cache,BaseForm form,String keyStr,MConsumerLoginVO loginVO) {
		clearPage(cache,FormPageConstants.CONSUMER_PAGE, loginVO);
		addPage(cache,form, FormPageConstants.CONSUMER_PAGE,loginVO);
	}
}
